//
//  CZQVipDetalChildViewController.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/16.
//  Copyright © 2018年 众拳科技. All rights reserved.
// 会员详情子控制器

#import "CZQVipDetalChildViewController.h"
#import "CZQVipDetalChildTableViewCell.h"
#import "CZQVipClassDetalTableViewCell.h"
#import "CZQVipDetailModel.h"
#import "CZQClassRecodeModel.h"
#import "AddVenueVipViewController.h"
#import "CZQVipPhotoViewController.h"
#import "SideViewController.h"
#import "VipCardViewController.h"
#import "CourseClassInfoViewController.h"
@interface CZQVipDetalChildViewController () <UITableViewDelegate,UITableViewDataSource>

/**
 //数据源
 */
@property(nonatomic,strong)NSMutableArray *dataArr;


/**
 tableView
 */
@property(nonatomic,weak)UITableView *tableView;
@end

@implementation CZQVipDetalChildViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self handleData];
}

-(void)handleData
{
    if (self.childType == 1) {
        
        //基本信息
        
        NSArray *picArr = @[@"icon_mobilephone",@"icon_birthday",@"icon_address",@"icn_time",@"icon_member"];
        NSArray *nameArr = @[@"手机",@"生日",@"地址",@"注册时间",@"会员等级"];
        
        for (int i = 0; i < picArr.count; i ++) {
            
            CZQVipDetailModel *model = [[CZQVipDetailModel alloc]init];
            
            model.infoName = nameArr[i];
            
            model.infoImageStr = picArr[i];
            
            [self.dataArr addObject:model];
            
        }
        
        
        
    }else if (self.childType == 2){
        
        //上课记录
        
        
    }else
    {
        //更多信息
        NSArray *nameArr = @[@"会员照片",@"体测数据",@"基本信息",@"会员卡",@"教练"];
        
        for (int i = 0; i < nameArr.count; i ++) {
            
            CZQVipDetailModel *model = [[CZQVipDetailModel alloc]init];
            
            model.infoName = nameArr[i];
            
            model.infoImageStr = nameArr[i];
            
            [self.dataArr addObject:model];
            
        }
        
    }
    
    [self.tableView reloadData];
    
}

#pragma mark -- 懒加载

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        
        _dataArr = [NSMutableArray array];
        
    }
    
    return _dataArr;
}

-(UITableView *)tableView
{
    if (!_tableView) {
        
        UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        
        tableView.delegate=self;
        
        tableView.dataSource=self;
        
        tableView.backgroundColor = BackGroundColor;
        
        tableView.estimatedRowHeight = 50;
        
        [self.view addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
            
        }];
        
        //        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
        //注册
        //                [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQVipDetalChildTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQVipDetalChildTableViewCell"];
        
        [tableView registerNib:[UINib nibWithNibName:@"CZQVipClassDetalTableViewCell" bundle:nil]  forCellReuseIdentifier:@"CZQVipClassDetalTableViewCell"];
        
        //        [tableView registerNib:[UINib nibWithNibName:@"YDTrainingTableViewCell" bundle:nil]  forCellReuseIdentifier:@"cell"];
        
        _tableView = tableView;
    }
    return _tableView;
}

#pragma mark - UITableViewDataSource

//行数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

//列数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count ;
}

//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.childType == 2) {
        //上课记录
    
        CZQVipClassDetalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQVipClassDetalTableViewCell"];
        
        cell.classModell = [self.dataArr objectAtIndex:indexPath.row];
        
        
        
        return cell;
    }
    
    CZQVipDetalChildTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CZQVipDetalChildTableViewCell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.vipModel = [self.dataArr objectAtIndex:indexPath.row];
    
    if (self.childType == 4) {
        //更多信息
        if (indexPath.row == 0) {
            
            //显示会员图片
            cell.icon.hidden = NO;
            
        }
        
        cell.nextView.hidden = NO;
    }else if(self.childType == 1){
        //基本信息
        NSArray *titleArr = @[self.venueVipModel.CellPhone,self.venueVipModel.Birthday,self.venueVipModel.Address,self.venueVipModel.AddTime,self.venueVipModel.Grade];
        cell.titleLable.text = titleArr[indexPath.row];
        
    }
    
    
    
    return cell  ;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.00001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.00001;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectZero];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[UIView alloc]initWithFrame:CGRectZero];
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //当离开某行时，让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.childType == 1) {
        
    }else if (self.childType == 2)
    {
        //上课记录
//        CourseClassInfoViewController *course = [CourseClassInfoViewController new];
//        
//        [self.navigationController pushViewController:course animated:YES];
        
    }else
    {
        //更多数据
        if (indexPath.row == 0) {
            //添加会员照片
            CZQVipPhotoViewController *vipPhoto = [CZQVipPhotoViewController new];
            
            vipPhoto.venueVipModel = self.venueVipModel;
            
            [self.navigationController pushViewController:vipPhoto animated:YES];
            
        }else if (indexPath.row == 1)
        {
            //体测数据
            SideViewController *sideVC = [[SideViewController alloc] init];
            
            sideVC.from = @"vipInfo";
            
            sideVC.venueVipModel = self.venueVipModel;
            
            [self.navigationController pushViewController:sideVC animated:YES];
            
        }
        else if (indexPath.row == 2)
        {
            //基本信息
            AddVenueVipViewController *addVenueVipVC = [[AddVenueVipViewController alloc] init];
            
            addVenueVipVC.venueVipModel = self.venueVipModel;
            
            [self.navigationController pushViewController:addVenueVipVC animated:YES];
            
        }
        else if (indexPath.row == 3)
        {
            //会员卡
            VipCardViewController *vipCard = [VipCardViewController new];
            
            [self.navigationController pushViewController:vipCard animated:YES];
        }
        
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
